import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Brand } from './Brand';

@Index('inventory_history_ibfk_1', ['brandId'], {})
@Entity('inventory_history', { schema: 'blog_back' })
export class InventoryHistory {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id', unsigned: true })
  id: number;

  @Column('int', {
    primary: true,
    name: 'brand_id',
    comment: '品牌Id',
    unsigned: true,
  })
  brandId: number;

  @Column('int', {
    name: 'customer_id',
    nullable: true,
    comment: '顾客id',
    unsigned: true,
  })
  customerId: number | null;

  @Column('enum', { name: 'type', comment: '-1出库，1入库', enum: ['-1', '1'] })
  type: '-1' | '1';

  @Column('int', {
    name: 'price',
    comment: '出库/入库 实际总价格',
    unsigned: true,
  })
  price: number;

  @Column('int', { name: 'nub', comment: '数量', unsigned: true })
  nub: number;

  @Column('int', {
    name: 'marketPrice',
    nullable: true,
    comment: '品牌当时的价格',
  })
  marketPrice: number | null;

  @Column('varchar', {
    name: 'description',
    nullable: true,
    comment: '描述',
    length: 255,
  })
  description: string | null;

  @Column('timestamp', {
    name: 'create_time',
    comment: '创建时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @Column('timestamp', {
    name: 'update_time',
    comment: '更新时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  @ManyToOne(() => Brand, (brand) => brand.inventoryHistories, {
    onDelete: 'RESTRICT',
    onUpdate: 'RESTRICT',
  })
  @JoinColumn([{ name: 'brand_id', referencedColumnName: 'id' }])
  brand: Brand;
}
